<script>
import {mapMutations} from 'vuex'
import Member from '@/api/member'
export default {
	globalData: {
		OPENID: null,
		USERINFO: {},
	},
	onLaunch: function() {
		console.log('App Launch');
		let _this = this;
		uni.getUserInfo({
			success(e) {
				const {errMsg, userInfo} = e
				if(errMsg !== "getUserInfo:ok") {
					uni.showModal({
						title: '提示',
						content: '您取消了授权登录，请重新授权',
						showCancel: false
					});
					//没有授权登录就用默认的用户信息
					_this.$store.commit('SET_MEMBER', Member)
				} else {
					const {avatarUrl: avatar, city, country, gender, nickName: nickname, province} = userInfo
					const member = Object.assign(Member, {avatar, city, country, gender, nickname, province})
					_this.globalData.USERINFO = member;
					_this.$store.commit('SET_MEMBER', member)
					uni.login({
						success(res) {
							if(res.errMsg === "login:ok") {
								_this.$request({
									url: `/login?code=${res.code}`
								}).then(res => {
									if(res.code === 0) {
										_this.globalData.OPENID = res.result;
									}
								})
							}
						}
					})
				}
				uni.navigateBack()
			}
		})
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style lang="scss">
/*每个页面公共css */
@import '~@/static/style/app.scss';
</style>
